// var postList = "http://localhost:8080/hjcr-wechat/article/queryArticlesInPage";
var postList = "./json/postList.json";

$(document).ready(function(){
  var i=0;
  var totalPage =0;
  function getRecord(num,size) {
    $.get(postList,{params:{currentPage:num,size:size}}, function(res){
      if(res.serviceResult){
        totalPage = res.resultParm.totalPages;
        var data = res.resultParm.articles.content;
        var html = "";
        for (var i = 0; i < data.length; i++) {
          html +=  '<div class="post-item">'+
                    '<span class="time">'+data[i].publishTime+'</span>'+
                    '<div class="card overview">'+
                      '<div class="cover"'+
                        'style="background-image: url('+data[i].coverUrl+');"'+
                      '></div>'+
                      '<h6>'+data[i].title+'</h6>'+
                    '</div>'+
                  '</div>';
        }
        $(".post").empty().append(html);
      }
    });

  }
  getRecord(0,15);
  $(document).scroll(function() {
    if(document.body.scrollHeight-document.body.scrollTop<=window.screen.availHeight){
      if(i<totalPage-1){
        getRecord(++i,15);
      }
    }
  });
});
